# Functionality for sandboxed execution, i.e. running code on an input and
# collecting its output.

licenses(["notice"])

package(
    default_visibility = ["//:__subpackages__"],
)

cc_library(
    name = "tester_sandboxer",
    srcs = ["tester_sandboxer.cc"],
    hdrs = ["tester_sandboxer.h"],
    deps = [
        ":simple_threadpool",
        ":status_macros",
        ":temp_path",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/synchronization",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:span",
        "@com_google_sandboxed_api//sandboxed_api/sandbox2",
        "@com_google_sandboxed_api//sandboxed_api/sandbox2:buffer",
        "@com_google_sandboxed_api//sandboxed_api/sandbox2/util:bpf_helper",
    ],
)

cc_library(
    name = "py_tester_sandboxer",
    srcs = ["py_tester_sandboxer.cc"],
    hdrs = ["py_tester_sandboxer.h"],
    deps = [
        ":status_macros",
        ":temp_path",
        ":tester_sandboxer",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:span",
        "@com_google_farmhash//:farmhash",
        "@com_google_sandboxed_api//sandboxed_api/sandbox2",
    ],
)

cc_test(
    name = "tester_sandboxer_test",
    srcs = ["tester_sandboxer_test.cc"],
    local = 1,
    tags = ["manual"],  # Run test by building and executing resulting binary.
    deps = [
        ":py_locations",
        ":py_tester_sandboxer",
        ":status_macros",
        ":status_matchers",
        ":tester_sandboxer",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/base:log_severity",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/synchronization",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:optional",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
        "@com_google_sandboxed_api//sandboxed_api/sandbox2",
    ],
)

cc_library(
    name = "py_locations",
    srcs = ["py_locations.cc"],
    hdrs = ["py_locations.h"],
    deps = ["@com_google_absl//absl/flags:flag"],
)

cc_binary(
    name = "solve_example",
    srcs = ["solve_example.cc"],
    deps = [
        ":py_locations",
        ":py_tester_sandboxer",
        ":status_macros",
        ":tester_sandboxer",
        "//:contest_problem_cc_proto",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/flags:parse",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
        "@com_google_riegeli//riegeli/bytes:fd_reader",
        "@com_google_riegeli//riegeli/records:record_reader",
    ],
)

cc_library(
    name = "status_macros",
    hdrs = ["status_macros.h"],
    deps = [
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/status",
    ],
)

cc_library(
    name = "status_matchers",
    testonly = 1,
    hdrs = ["status_matchers.h"],
    deps = [
        ":status_macros",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:optional",
        "@com_google_googletest//:gtest",
    ],
)

cc_library(
    name = "temp_path",
    hdrs = ["temp_path.h"],
    deps = [
        "@com_google_absl//absl/random",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/time",
    ],
)

cc_library(
    name = "simple_threadpool",
    hdrs = ["simple_threadpool.h"],
    deps = [
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/synchronization",
    ],
)
